// DisplayAttributeSequence.cpp: implementation of the CDisplayAttributeSequence class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "AnsiTerminal.h"
#include "DisplayAttributeSequence.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CDisplayAttributeSequence::CDisplayAttributeSequence(IDisplayAttribute *pDisplayAttribute) :
	CAnsiSequence(FINAL_CHAR_DISPLAYATTRIBUTE)
{
	m_pDisplayAttribute = pDisplayAttribute;
}

CDisplayAttributeSequence::~CDisplayAttributeSequence()
{

}

void CDisplayAttributeSequence::SetParameters(const CString& params)
{
	CString part;
	int count = params.GetLength();
	const char *szParams = params;
	for(int n = 0; n <= count; n++)
	{
		if(szParams[n] == ';' || n == count)
		{
			int val = atoi(part);
			if(val >= 30 && val <= 37)
			{
				m_pDisplayAttribute->SetForecolor(ANSI_COLOR(val - 30));
			}
			else if(val >= 40 && val <= 47)
			{
				m_pDisplayAttribute->SetBackcolor(ANSI_COLOR(val - 40));
			}
			else if(val == 0)
			{
				m_pDisplayAttribute->ResetAttribute();
			}
			else if(val == 1)
			{
				m_pDisplayAttribute->SetHighlight(TRUE);
			}
			else if(val == 4)
			{
				m_pDisplayAttribute->SetUnderline(TRUE);
			}
			else if(val == 5)
			{
				m_pDisplayAttribute->SetBlink(TRUE);
			}
			else if(val == 7)
			{
				m_pDisplayAttribute->SetInverse(TRUE);
			}
			else
			{
				// simple ignore
			}
			part.Empty();
		}
		else
		{
			part += szParams[n];
		}
	}
}
